package main

import (
	"bytes"
	"fmt"
)

func main1() {
	s := []int{0, 1, 2, 3, 4, 5}
	// Rotate s left by two positions.
	reverse(s)

	reverse(s[:2])
	reverse(s[2:])
	fmt.Println(s)
}

func main2() {
	a := [...]int{0, 1, 2, 3, 4, 5}
	reverse(a[:])
	fmt.Println(a) // "[5 4 3 2 1 0]"
}

func main3() {
	a := []string{"a", "b"}
	b := []string{"a", "b"}
	fmt.Println(equal(a, b))
}

func main4() {
	a := "test1"
	b := "test2"

	ab := []byte(a)
	bb := []byte(b)
	fmt.Println(ab)
	fmt.Println(bb)
	fmt.Println(bytes.Equal(ab, bb))
}

func main5() {
	var s []int // len(s) == 0, s == nil
	fmt.Println(s)
	s = nil // len(s) == 0, s == nil
	fmt.Println(s)
	s = []int(nil) // len(s) == 0, s == nil
	fmt.Println(s)
	s = []int{} // len(s) == 0, s != nil
	fmt.Println(s)
}

func main() {
	var runes []rune
	for _, r := range "Hello, 世界" {
		fmt.Println(r)
		runes = append(runes, r)
	}
	fmt.Printf("%q\n", runes)
}

func reverse(s []int) {
	for i, j := 0, len(s)-1; i < j; i, j = i+1, j-1 {
		s[i], s[j] = s[j], s[i]
	}
}

func equal(x, y []string) bool {
	if len(x) != len(y) {
		return false
	}
	for i := range x {
		if x[i] != y[i] {
			return false
		}
	}
	return true
}
